package com.ewzj.bigdata.mvp.ui.fragment

import android.content.Intent
import android.os.Bundle
import android.support.v4.widget.SwipeRefreshLayout
import android.support.v7.widget.LinearLayoutManager
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.chad.library.adapter.base.BaseQuickAdapter
import com.ewzj.bigdata.R
import com.ewzj.bigdata.app.extensions.dpToPx
import com.ewzj.bigdata.app.extensions.initcolor
import com.ewzj.bigdata.di.component.DaggerOrginNewsFragmentComponent
import com.ewzj.bigdata.di.module.OrginNewsFragmentModule
import com.ewzj.bigdata.mvp.contract.OrginNewsFragmentContract
import com.ewzj.bigdata.mvp.presenter.OrginNewsFragmentPresenter
import com.ewzj.bigdata.mvp.ui.adapter.OriginAdapter
import com.jess.arms.base.BaseFragment
import com.jess.arms.di.component.AppComponent
import com.yqritc.recyclerviewflexibledivider.HorizontalDividerItemDecoration
import kotlinx.android.synthetic.main.fragment_orginnew.*

/**
 * author:zhangjing
 * 作用:
 * return:
 */
class OrginNewsFragment:BaseFragment<OrginNewsFragmentPresenter>(),OrginNewsFragmentContract.View {
    override fun initRecylerview(adapter: OriginAdapter) {
        rvnews.layoutManager=LinearLayoutManager(activity)
        adapter.setOnLoadMoreListener(object : BaseQuickAdapter.RequestLoadMoreListener {
            override fun onLoadMoreRequested() {
                mPresenter.loadmoreData()
            }

        },rvnews)
        rvnews.adapter=adapter
    }

    companion object {
        fun newInstance(): OrginNewsFragment {
            val fragment = OrginNewsFragment();
            val args = Bundle()
            fragment.arguments = args;
            return fragment
        }
    }

    override fun setupFragmentComponent(appComponent: AppComponent?) {
        DaggerOrginNewsFragmentComponent.builder()
                .appComponent(appComponent)
                .orginNewsFragmentModule(OrginNewsFragmentModule(this))
                .build()
                .inject(this)
    }

    override fun initData(savedInstanceState: Bundle?) {
        rvnews.addItemDecoration(HorizontalDividerItemDecoration.Builder(activity).colorResId(R.color.colorf7).size(5.dpToPx(activity)).build())
        swipeRefreshLayout.initcolor()
        swipeRefreshLayout.setOnRefreshListener(object : SwipeRefreshLayout.OnRefreshListener {
            override fun onRefresh() {
                mPresenter.getFirstData()
            }

        });
        mPresenter.initRecyadapter()
        mPresenter.getFirstData()
    }

    override fun setData(data: Any?) {

    }

    override fun onResume() {
        super.onResume()
        mPresenter.onreusme()
    }
    override fun initView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View {
        val view=inflater!!.inflate(R.layout.fragment_orginnew,null,false);
        return view
    }

    override fun showLoading() {
        swipeRefreshLayout.isRefreshing=true
    }

    override fun launchActivity(intent: Intent?) {

    }

    override fun hideLoading() {
        swipeRefreshLayout.isRefreshing=false
    }

    override fun killMyself() {

    }

    override fun showMessage(message: String?) {

    }

}